package com.woorigil.social.domain.category;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.woorigil.social.Context;
import com.woorigil.social.domain.deal.Deal;

@Component (value="WMMapper")
public class WemakepriceCategoryMapper implements CategoryMapper {
	Map<String, List<String>> shoppings = new HashMap<String, List<String>>() {{
		put("가전", Arrays.asList("생활가전", "주방가전"));
		put("생활/주방", Arrays.asList("생황용품", "주방/욕실"));
		put("출산/유아동", Arrays.asList("출산/유아용품", "유아패션/케어", "완구/교구/도서"));
		put("뷰티", Arrays.asList("건강/다이어트", "메이크업", "이미용/다이어트", "바디/헤어", "스킨케어"));
		put("식품", Arrays.asList("신선식품", "유아식품/생활", "가공식품", "커피/차/음료"));
		put("스포츠/레저", Arrays.asList("스포츠"));
		put("디지털", Arrays.asList("컴퓨터/주변기기", "디지털/자동차"));
		put("패션잡화", Arrays.asList("가방/지갑", "슈즈", "액세서리/소품"));
		put("홈/데코/취미", Arrays.asList("홈인테리어"));
		put("의류", Arrays.asList("전국"));
	}};
	Map<String, List<String>> travels = new HashMap<String, List<String>>() {{
		put("레저/스포츠", Arrays.asList("레저/취미/기타"));
		put("숙박", Arrays.asList("호텔/리조트/펜션"));
//		put("제주", Arrays.asList(""));
		put("국내", Arrays.asList("국내여행"));
		put("해외", Arrays.asList("해외여행/항공권", "해외여행"));
	}};
	Map<String, List<String>> cultures = new HashMap<String, List<String>>() {{
		put("뮤지컬/연극", Arrays.asList("공연/전시"));
	}};
	Map<String, List<String>> locals = new HashMap<String, List<String>>() {{
		put("서울", Arrays.asList("스페셜(서울)", "명동/이태원", "홍대/마포", "신촌/이대/은평", "강남/신논현/논현", "관악/구로/동작", "동대문/성북", "삼성/역삼/선릉/대치", "압구정/청담/신사", "종로/대학로", "서초/교대/양재/반포", "강동/천호/길동", "중구", "서울베스트", "노원/수유", "광진/건대/왕십리", "영등포/양천/강서", "송파/잠실/가락"));
		put("경기", Arrays.asList("분당/성남/판교", "용인/광주", "구리/남양주", "김포/강화", "의정부/동두천", "일산/파주", "광명/시흥", "안양/안산/군포/의왕", "수원/화성/오산", "하남/포천"));
		put("인천", Arrays.asList("인천", "인천/부천베스트", "부천"));
		put("대전", Arrays.asList("유성구", "서구", "대덕구", "동구", "대전베스트"));
		put("충청", Arrays.asList("청주/충주", "천안/아산"));
		put("대구", Arrays.asList("달서구/남구", "대구베스트", "중구/서구", "수성구/경산"));
		put("부산", Arrays.asList("해운대/광안/경성대", "남포/사상/북구", "서면/연산/동래", "동구/북구"));
		put("경상", Arrays.asList("", ""));
		put("전라", Arrays.asList("전주/군산/익산", ""));
		put("광주", Arrays.asList("북구", "광주베스트", "동구/남구", "광산구"));
		put("강원", Arrays.asList("원주/춘천", ""));
		put("제주", Arrays.asList("제주", ""));
	}};

	@Override
	public int getCategoryId(Deal deal) {
		int categoryId = 0;
		Box box = getCategoryBox(deal.getSection1(), deal.getCategory());
		if (box != null) {
			categoryId = Context.getCategoryId(box.getLevel2());
		}
		return (categoryId == 0)? 100 : categoryId;
	}
	
	private Box getCategoryBox(String sectionName1, String sectionName2) {
		for (String subMenu : shoppings.keySet()) {
			List<String> shoppingSectionNames = shoppings.get(subMenu);
			if (shoppingSectionNames.contains(sectionName1)) {
				String level2 = getSubMenuName(subMenu, sectionName2);
				return new Box("쇼핑", level2);
			}
		}
		for (String subMenu : travels.keySet()) {
			List<String> shoppingSectionNames = travels.get(subMenu);
			if (shoppingSectionNames.contains(sectionName1)) {
				String level2 = getSubMenuName(subMenu, sectionName2);
				return new Box("여행/레저", level2);
			}
		}
		for (String subMenu : cultures.keySet()) {
			List<String> shoppingSectionNames = cultures.get(subMenu);
			if (shoppingSectionNames.contains(sectionName1)) {
				String level2 = getSubMenuName(subMenu, sectionName2);
				return new Box("문화", level2);
			}
		}
		for (String subMenu : locals.keySet()) {
			List<String> shoppingSectionNames = locals.get(subMenu);
			if (shoppingSectionNames.contains(sectionName1)) {
				String level2 = getSubMenuName(subMenu, sectionName2);
				return new Box("지역", level2);
			}
		}
		return null;
	}
	
	private String getSubMenuName(String subMenu, String sectionName2) {
		if ("전국".equals(subMenu)) {
			if (sectionName2.contains("의류")) {
				return "의류";
			}
		}
		return subMenu;
	}
	
	public class Box {
		private String level1;
		private String level2;
		
		public Box(String level1, String level2) {
			this.level1 = level1;
			this.level2 = level2;
		}
		
		public String getLevel1() {
			return level1;
		}
		public void setLevel1(String level1) {
			this.level1 = level1;
		}
		public String getLevel2() {
			return level2;
		}
		public void setLevel2(String level2) {
			this.level2 = level2;
		}
	}
}
